package com.mccken.delay;

import java.util.concurrent.DelayQueue;

import cn.hutool.json.JSONUtil;
import lombok.SneakyThrows;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-03-19 17:13
 **/
public class Demo1 {

	private static final DelayQueue<MyDelayTask> queue = new DelayQueue<>();

	private static void doSomething() {

		while (true) {
			try {
				MyDelayTask take = queue.take();
				System.out.println(JSONUtil.toJsonStr(take));
			} catch (Exception e) {

			}
		}
	}

	@SneakyThrows
	public static void main(String[] args) {

		MyDelayTask dto1 = new MyDelayTask(1000L);
		MyDelayTask dto5 = new MyDelayTask(5000L);
		MyDelayTask dto10 = new MyDelayTask(10 * 1000L);
		MyDelayTask dto30 = new MyDelayTask(30 * 1000L);
		queue.add(dto30);
		queue.add(dto5);
		queue.add(dto1);
		queue.add(dto10); 

		System.out.println();

		new Thread(() -> {
			Demo1.doSomething();
		}).start();

		int i = 0;
		while (true) {
			i++;
		}
	}

}
